﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using FlexCell;
using YJKArchUtils.Utils;
using YJKExcelTableUtil;
using YJKWndrStatisticsExcel.AreaTable.DataManager;
using YJKWndrStatisticsExcel.AreaTable.Forms;
using YJKWndrStatisticsExcel.AreaTable.YJKExcelFormTool;

namespace YJKWndrStatisticsExcel.AreaTable.StatisticControler
{
	public class StatisticalControler
	{
		public StatisticalControler(ExternalCommandData cmdData)
		{
			this.m_Revit = cmdData;
		}

		public bool Statistical()
		{
			StatisticalResultData resultData = null;
			if (!this.StatisticalAreaInfo(ref resultData))
			{
				return false;
			}
			StatisticalResultForm statisticalResultForm = new StatisticalResultForm(resultData);
			statisticalResultForm.TableIndex = 0;
			while (statisticalResultForm.ShowDialog() == DialogResult.OK)
			{
				if (statisticalResultForm.m_nDlgResult == 0u)
				{
					this.DrawingTable(statisticalResultForm.TableIndex, resultData);
				}
				else
				{
					this.ExportExcelFile(statisticalResultForm.TableIndex, resultData);
				}
			}
			return true;
		}

		private bool StatisticalAreaInfo(ref StatisticalResultData resultData)
		{
			List<Level> sortLevels = Common.GetSortLevels(this.m_Revit.Application.ActiveUIDocument.Document, double.MinValue, double.MaxValue);
			List<ViewPlan> allFloors = this.GetAllFloors();
			for (int i = 0; i < sortLevels.Count; i++)
			{
				bool flag = false;
				using (List<ViewPlan>.Enumerator enumerator = allFloors.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						if (enumerator.Current.GenLevel.Id.IntegerValue == sortLevels[i].Id.IntegerValue)
						{
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					sortLevels.RemoveAt(i);
					i--;
				}
			}
			List<ViewPlan> list = new List<ViewPlan>();
			List<ViewPlan> list2 = new List<ViewPlan>();
			this.GetAllAreaInfos(sortLevels, ref list, ref list2);
			List<int> list3 = new List<int>();
			if (!this.SelectStatisticalRange(sortLevels, list, list2, ref list3))
			{
				return false;
			}
			List<StatisticalCalculater.AreaViewsInfoByFloor> list4 = new List<StatisticalCalculater.AreaViewsInfoByFloor>();
			foreach (int index in list3)
			{
				Level level = sortLevels[index];
				ViewPlan fillAreaView = list[index];
				ViewPlan suiteAreaView = list2[index];
				StatisticalCalculater.AreaViewsInfoByFloor item = new StatisticalCalculater.AreaViewsInfoByFloor(level, fillAreaView, suiteAreaView);
				list4.Add(item);
			}
			new StatisticalCalculater(this.m_Revit).Calculate(list4, ref resultData);
			return true;
		}

		private List<ViewPlan> GetAllFloors()
		{
			List<ViewPlan> list = new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(ViewPlan)).Cast<ViewPlan>().ToList<ViewPlan>();
			List<ViewPlan> list2 = new List<ViewPlan>();
			foreach (ViewPlan viewPlan in list)
			{
				if ((int)viewPlan.ViewType == 1 && viewPlan.GenLevel != null)
				{
					list2.Add(viewPlan);
				}
			}
			return list2;
		}

		private bool SelectStatisticalRange(List<Level> sortedLevelList, List<ViewPlan> sortedFillAreaViewListByLevel, List<ViewPlan> sortedSuiteAreaViewListByLevel, ref List<int> selectIndex)
		{
			List<StatisticalSettingForm.AreaViewsInfoByFloor> list = new List<StatisticalSettingForm.AreaViewsInfoByFloor>();
			for (int i = 0; i < sortedLevelList.Count; i++)
			{
				string name = sortedLevelList[i].Name;
				List<StatisticalSettingForm.AreaViewInfo> list2 = new List<StatisticalSettingForm.AreaViewInfo>();
				if (sortedFillAreaViewListByLevel[i] != null)
				{
					string areaViewName = sortedFillAreaViewListByLevel[i].AreaScheme.Name + "(建筑总面积视图)";
					AreaType areaType = AreaType.AT_Fill;
					StatisticalSettingForm.AreaViewInfo item = new StatisticalSettingForm.AreaViewInfo(areaViewName, areaType);
					list2.Add(item);
				}
				if (sortedSuiteAreaViewListByLevel[i] != null)
				{
					string areaViewName2 = sortedSuiteAreaViewListByLevel[i].AreaScheme.Name + "(套型面积视图)";
					AreaType areaType2 = AreaType.AT_Suite;
					StatisticalSettingForm.AreaViewInfo item2 = new StatisticalSettingForm.AreaViewInfo(areaViewName2, areaType2);
					list2.Add(item2);
				}
				if (sortedFillAreaViewListByLevel[i] != null && sortedSuiteAreaViewListByLevel[i] != null)
				{
					StatisticalSettingForm.AreaViewsInfoByFloor item3 = new StatisticalSettingForm.AreaViewsInfoByFloor(name, true, list2);
					list.Add(item3);
				}
				else
				{
					StatisticalSettingForm.AreaViewsInfoByFloor item4 = new StatisticalSettingForm.AreaViewsInfoByFloor(name, false, list2);
					list.Add(item4);
				}
			}
			StatisticalSettingForm statisticalSettingForm = new StatisticalSettingForm(list);
			if (statisticalSettingForm.ShowDialog() != DialogResult.OK)
			{
				return false;
			}
			selectIndex = statisticalSettingForm.SelectIndex();
			return true;
		}

		private void GetAllAreaInfos(List<Level> sortedLevelList, ref List<ViewPlan> sortedFillAreaViewListByLevel, ref List<ViewPlan> sortedSuiteAreaViewListByLevel)
		{
			Document document = this.m_Revit.Application.ActiveUIDocument.Document;
			foreach (Level level in sortedLevelList)
			{
				sortedFillAreaViewListByLevel.Add(null);
				sortedSuiteAreaViewListByLevel.Add(null);
			}
			foreach (Element element in new FilteredElementCollector(document).OfClass(typeof(ViewPlan)))
			{
				ViewPlan viewPlan = element as ViewPlan;
				if (viewPlan != null && (int)viewPlan.ViewType == 116)
				{
					AreaType areaType = AreaType.AT_None;
					this.HasStatisticalDataInView(viewPlan.Id, document, ref areaType);
					if (areaType != AreaType.AT_None)
					{
						Level genLevel = viewPlan.GenLevel;
						int num = sortedLevelList.FindIndex((Level value) => value.Id.IntegerValue == genLevel.Id.IntegerValue);
						if (num != -1)
						{
							if (areaType == AreaType.AT_Fill)
							{
								sortedFillAreaViewListByLevel[num] = viewPlan;
							}
							else
							{
								sortedSuiteAreaViewListByLevel[num] = viewPlan;
							}
						}
					}
				}
			}
		}

		private bool HasStatisticalDataInView(ElementId viewId, Autodesk.Revit.DB.Document doc, ref AreaType areaType)
		{
			foreach (Element element in new FilteredElementCollector(doc, viewId).OfCategory(BuiltInCategory.OST_Areas))
			{
				Area area = element as Area;
				if (area != null && AreaInfoManager.HaxExtensibleStorageInArea(area, ref areaType))
				{
					return true;
				}
			}
			return false;
		}

		private void DrawingTable(int tableIndex, StatisticalResultData resultData)
		{
			switch (tableIndex)
			{
			case 0:
				this.DrawArchAreaStatisticalTable(resultData.m_AASData);
				return;
			case 1:
				this.DrawEstateSuiteAreaStatisticalTable(resultData.m_FloorNameList, resultData.m_ESASData);
				return;
			case 2:
				this.DrawHouseSuiteAreaStatisticalTable(resultData.m_FloorNameList, resultData.m_HSASData);
				return;
			case 3:
				this.DrawHouseSuiteAreaAnalyzeTable(resultData.m_HSAAData);
				return;
			default:
				return;
			}
		}

		private void DrawArchAreaStatisticalTable(ArchAreaStatisticalData AASData)
		{
			int num = 0;
			int num2 = 0;
			List<CellInfo> list = new List<CellInfo>();
			list.Add(new CellInfo(num, 2, num2++, 1, "楼层"));
			list.Add(new CellInfo(num, 1, num2, 3, "分户"));
			list.Add(new CellInfo(num++, 1, num2 + 3, 6, "面积分类(㎡)"));
			list.Add(new CellInfo(num, 1, num2++, 1, "户号"));
			list.Add(new CellInfo(num, 1, num2++, 1, "编号"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套型"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套内使用面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套内墙体面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "阳台面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套内建筑面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "分摊面积"));
			list.Add(new CellInfo(num++, 1, num2++, 1, "建筑面积(含阳台)"));
			AASData.ToGridCellList(ref num, ref list);
			this.DrawCellsGrid(list, num, num2);
		}

		private void DrawEstateSuiteAreaStatisticalTable(List<string> floorNameList, List<EstateSuiteAreaStatisticalData> ESASData)
		{
			int num = 0;
			int num2 = 0;
			List<CellInfo> list = new List<CellInfo>();
			list.Add(new CellInfo(num, 2, num2++, 1, "编号"));
			list.Add(new CellInfo(num, 2, num2++, 1, "套型"));
			list.Add(new CellInfo(num, 1, num2, 6, "面积分类(㎡)"));
			list.Add(new CellInfo(num++, 1, num2 + 6, floorNameList.Count + 1, "套数"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套内使用面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套内墙体面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "阳台面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套内建筑面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "分摊面积"));
			list.Add(new CellInfo(num, 1, num2++, 1, "建筑面积(含阳台)"));
			foreach (string value in floorNameList)
			{
				list.Add(new CellInfo(num, 1, num2++, 1, value));
			}
			list.Add(new CellInfo(num++, 1, num2++, 1, "合计"));
			foreach (EstateSuiteAreaStatisticalData estateSuiteAreaStatisticalData in ESASData)
			{
				estateSuiteAreaStatisticalData.ToGridCellList(ref num, ref list);
			}
			this.DrawCellsGrid(list, num, num2);
		}

		private void DrawHouseSuiteAreaStatisticalTable(List<string> floorNameList, List<HouseSuiteAreaStatisticalData> HSASData)
		{
			int num = 0;
			int num2 = 0;
			List<CellInfo> list = new List<CellInfo>();
			list.Add(new CellInfo(num, 2, num2++, 1, "编号"));
			list.Add(new CellInfo(num, 2, num2++, 1, "套型"));
			list.Add(new CellInfo(num, 1, num2, 4, "面积分类(㎡)"));
			list.Add(new CellInfo(num++, 1, num2 + 4, floorNameList.Count + 1, "套数"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套内使用面积 S1"));
			list.Add(new CellInfo(num, 1, num2++, 1, "分摊面积 S2"));
			list.Add(new CellInfo(num, 1, num2++, 1, "套型建筑面积 S1+S2"));
			list.Add(new CellInfo(num, 1, num2++, 1, "阳台面积"));
			foreach (string value in floorNameList)
			{
				list.Add(new CellInfo(num, 1, num2++, 1, value));
			}
			list.Add(new CellInfo(num++, 1, num2++, 1, "合计"));
			foreach (HouseSuiteAreaStatisticalData houseSuiteAreaStatisticalData in HSASData)
			{
				houseSuiteAreaStatisticalData.ToGridCellList(ref num, ref list);
			}
			this.DrawCellsGrid(list, num, num2);
		}

		private void DrawHouseSuiteAreaAnalyzeTable(List<HouseSuiteAreaAnalyzeData> HSAAData)
		{
			int num = 0;
			int columnSize = 0;
			List<CellInfo> list = new List<CellInfo>();
			list.Add(new CellInfo(num, 1, columnSize++, 1, "分类"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "套型"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "编号"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "套内使用面积 S1"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "分摊面积 S2"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "套型建筑面积 S1+S2"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "阳台面积"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "套数 N"));
			list.Add(new CellInfo(num, 1, columnSize++, 1, "套型总面积(S1+S2)*N"));
			list.Add(new CellInfo(num++, 1, columnSize++, 1, "比例"));
			foreach (HouseSuiteAreaAnalyzeData houseSuiteAreaAnalyzeData in HSAAData)
			{
				houseSuiteAreaAnalyzeData.ToGridCellList(ref num, ref list);
			}
			this.DrawCellsGrid(list, num, columnSize);
		}

		private void DrawCellsGrid(List<CellInfo> cellsGrid, int rowSize, int columnSize)
		{
			TableHead._Tag_HeadType tableHeadType = TableHead._Tag_HeadType.HT_CUSTOM;
			TableSourceInfo tableSourceInfo = new TableSourceInfo();
			double item = Common.MMToFeet(10.0);
			List<double> list = new List<double>();
			for (int i = 0; i < rowSize; i++)
			{
				list.Add(item);
			}
			double item2 = Common.MMToFeet(40.0);
			List<double> list2 = new List<double>();
			for (int i = 0; i < columnSize; i++)
			{
				list2.Add(item2);
			}
			List<TableHeadCell> list3 = new List<TableHeadCell>();
			foreach (CellInfo cellInfo in cellsGrid)
			{
				TableHeadCellKey key = new TableHeadCellKey();
				TableHeadCell item3 = new TableHeadCell(cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.Value, key);
				list3.Add(item3);
			}
			TableHead tableHeadData = new TableHead(tableHeadType, tableSourceInfo, list3, rowSize, columnSize, list, list2);
			TableBody tableBodyData = new TableBody();
			TextNoteType labelTextNoteType = this.GetLabelTextNoteType();
			double hMargin = 1.0;
			double vMargin = 1.5;
			TableInfos tableInfos = new TableInfos(tableHeadData, tableBodyData, labelTextNoteType, hMargin, vMargin, true);
			this.TestDrawGrid(tableInfos);
		}

		private TextNoteType GetLabelTextNoteType()
		{
			string strB = "宋体 3mm";
			string text = "TableGrid";
			int num = 0;
			TextNoteType textNoteType = null;
			TextNoteType textNoteType2 = null;
			TextNoteType textNoteType3 = null;
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document);
			filteredElementCollector.OfClass(typeof(TextNoteType));
			FilteredElementIterator elementIterator = filteredElementCollector.GetElementIterator();
			elementIterator.Reset();
			while (elementIterator.MoveNext())
			{
				Element element = elementIterator.Current;
				TextNoteType textNoteType4 = element as TextNoteType;
				if (textNoteType4 != null)
				{
					if (textNoteType4.Name.CompareTo(text) == 0)
					{
						textNoteType = textNoteType4;
						break;
					}
					if (textNoteType2 == null && textNoteType4.Name.CompareTo(strB) == 0)
					{
						textNoteType2 = textNoteType4;
					}
					textNoteType3 = textNoteType4;
				}
			}
			Transaction transaction = null;
			try
			{
				transaction = new Transaction(this.m_Revit.Application.ActiveUIDocument.Document);
				transaction.Start("new textNoteType");
				if (textNoteType == null)
				{
					if (textNoteType3 == null)
					{
						return null;
					}
					if (textNoteType2 == null)
					{
						textNoteType2 = textNoteType3;
					}
					textNoteType = (textNoteType2.Duplicate(text) as TextNoteType);
					double num2 = Common.MMToFeet(5.0);
					textNoteType.get_Parameter(BuiltInParameter.TEXT_SIZE).Set(num2);
					string text2 = "FangSong_GB2312";
					textNoteType.get_Parameter(BuiltInParameter.TEXT_FONT).Set(text2);
					double num3 = 0.7;
					textNoteType.get_Parameter(BuiltInParameter.TEXT_WIDTH_SCALE).Set(num3);
					double num4 = Common.MMToFeet(8.0);
					textNoteType.get_Parameter(BuiltInParameter.TEXT_TAB_SIZE).Set(num4);
					textNoteType.get_Parameter(BuiltInParameter.LINE_COLOR).Set(num);
				}
				transaction.Commit();
			}
			catch (Exception)
			{
				transaction.RollBack();
				return textNoteType;
			}
			return textNoteType;
		}

		private bool TestDrawGrid(TableInfos tableInfos)
		{
			TableDrawingToRevitKit tableDrawingToRevitKit = new TableDrawingToRevitKit(this.m_Revit, tableInfos);
			try
			{
				tableDrawingToRevitKit.Drawing();
			}
			catch
			{
				return false;
			}
			return true;
		}

		private void ExportExcelFile(int tableIndex, StatisticalResultData resultData)
		{
            FlexCell.Grid grid = null;
			switch (tableIndex)
			{
			case 0:
				this.ExporXlsArchAreaStatisticalTable(resultData.m_AASData, ref grid);
				break;
			case 1:
				this.ExporXlsEstateSuiteAreaStatisticalTable(resultData.m_FloorNameList, resultData.m_ESASData, ref grid);
				break;
			case 2:
				this.ExportXlsHouseSuiteAreaStatisticalTable(resultData.m_FloorNameList, resultData.m_HSASData, ref grid);
				break;
			case 3:
				this.ExportXlsHouseSuiteAreaAnalyzeTable(resultData.m_HSAAData, ref grid);
				break;
			}
			if (grid == null)
			{
				return;
			}
			for (int i = 1; i < grid.Cols; i++)
			{
				grid.Column(i).AutoFit();
			}
			grid.Range(2, 1, grid.Rows - 1, 1).Alignment = AlignmentEnum.LeftCenter;
			string filePath = "";
			int num = 0;
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.Filter = "Excel文件|*.xls|Excel文件|*.xlsx";
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				filePath = saveFileDialog.FileName;
				num = saveFileDialog.FilterIndex;
			}
			if (num == 1)
			{
				new GridToolExportImportExcel(false).ExportExcel(grid, filePath);
				return;
			}
			if (num != 2)
			{
				new GridToolExportImportExcel(false).ExportExcel(grid, filePath);
				return;
			}
			new GridToolExportImportExcel(true).ExportExcel(grid, filePath);
		}

        private void ExporXlsArchAreaStatisticalTable(ArchAreaStatisticalData AASData, ref FlexCell.Grid grid)
		{
            grid = new FlexCell.Grid();
			grid.Cols = 10;
			int num = 1;
			foreach (ArchAreaStatisticalFloorData archAreaStatisticalFloorData in AASData.m_Data)
			{
				num += archAreaStatisticalFloorData.m_Data.Count;
				num += 2;
			}
			num++;
			grid.Rows = num + 1;
			grid.Cell(1, 1).Text = "楼层\\户号";
			grid.Cell(1, 2).Text = "编号";
			grid.Cell(1, 3).Text = "套型";
			grid.Cell(1, 4).Text = "套内使用面积";
			grid.Cell(1, 5).Text = "套内墙体面积";
			grid.Cell(1, 6).Text = "阳台面积";
			grid.Cell(1, 7).Text = "套内建筑面积";
			grid.Cell(1, 8).Text = "分摊面积";
			grid.Cell(1, 9).Text = "建筑面积(含阳台)";
			int num2 = 2;
			for (int i = 0; i < AASData.m_Data.Count; i++)
			{
				ArchAreaStatisticalFloorData archAreaStatisticalFloorData2 = AASData.m_Data[i];
				grid.Cell(num2, 1).Text = archAreaStatisticalFloorData2.m_FloorName;
				num2++;
				for (int j = 0; j < archAreaStatisticalFloorData2.m_Data.Count; j++)
				{
					List<string> lstValue = archAreaStatisticalFloorData2.m_Data[j].ToStrList();
					this.InsertDataByRow(lstValue, 2, ref grid, ref num2);
				}
				List<string> lstValue2 = archAreaStatisticalFloorData2.m_FloorFooting.ToStrList();
				this.InsertDataByRow(lstValue2, 2, ref grid, ref num2);
			}
			List<string> lstValue3 = AASData.m_Footing.ToStrList();
			this.InsertDataByRow(lstValue3, 1, ref grid, ref num2);
		}

        private void ExporXlsEstateSuiteAreaStatisticalTable(List<string> floorNameList, List<EstateSuiteAreaStatisticalData> ESASData, ref FlexCell.Grid grid)
		{
            grid = new FlexCell.Grid();
			grid.Cols = 10 + floorNameList.Count;
			grid.Rows = ESASData.Count + 2;
			grid.Cell(1, 1).Text = "编号";
			grid.Cell(1, 2).Text = "套型";
			grid.Cell(1, 3).Text = "室内使用面积";
			grid.Cell(1, 4).Text = "套内墙体面积";
			grid.Cell(1, 5).Text = "阳台面积";
			grid.Cell(1, 6).Text = "套内建筑面积";
			grid.Cell(1, 7).Text = "分摊面积";
			grid.Cell(1, 8).Text = "建筑面积(含阳台)";
			int num = 9;
			for (int i = 0; i < floorNameList.Count; i++)
			{
				grid.Cell(1, num).Text = floorNameList[i];
				num++;
			}
			grid.Cell(1, num).Text = "合计";
			int num2 = 2;
			for (int j = 0; j < ESASData.Count; j++)
			{
				List<string> lstValue = ESASData[j].ToStrList();
				this.InsertDataByRow(lstValue, 1, ref grid, ref num2);
			}
		}

        private void ExportXlsHouseSuiteAreaStatisticalTable(List<string> floorNameList, List<HouseSuiteAreaStatisticalData> HSASData, ref FlexCell.Grid grid)
		{
            grid = new FlexCell.Grid();
			grid.Cols = 10 + floorNameList.Count;
			grid.Rows = HSASData.Count + 2;
			grid.Cell(1, 1).Text = "编号";
			grid.Cell(1, 2).Text = "套型";
			grid.Cell(1, 3).Text = "室内使用面积 S1";
			grid.Cell(1, 4).Text = "分摊面积 S2";
			grid.Cell(1, 5).Text = "套型建筑面积 S1+S2";
			grid.Cell(1, 6).Text = "阳台面积";
			int num = 7;
			for (int i = 0; i < floorNameList.Count; i++)
			{
				grid.Cell(1, num).Text = floorNameList[i];
				num++;
			}
			grid.Cell(1, num).Text = "合计";
			int num2 = 2;
			for (int j = 0; j < HSASData.Count; j++)
			{
				List<string> lstValue = HSASData[j].ToStrList();
				this.InsertDataByRow(lstValue, 1, ref grid, ref num2);
			}
		}

        private void ExportXlsHouseSuiteAreaAnalyzeTable(List<HouseSuiteAreaAnalyzeData> HSAAData, ref FlexCell.Grid grid)
		{
            grid = new FlexCell.Grid();
			grid.Cols = 9;
			int num = 0;
			foreach (HouseSuiteAreaAnalyzeData houseSuiteAreaAnalyzeData in HSAAData)
			{
				foreach (HouseSuiteAreaAnalyzeListBySuite houseSuiteAreaAnalyzeListBySuite in houseSuiteAreaAnalyzeData.m_Data)
				{
					num += houseSuiteAreaAnalyzeListBySuite.m_Data.Count;
					num += 2;
				}
				num += 2;
			}
			num++;
			grid.Rows = num + 1;
			grid.Cell(1, 1).Text = "分类\\套型\\编号";
			grid.Cell(1, 2).Text = "套内使用面积 S1";
			grid.Cell(1, 3).Text = "分摊面积 S2";
			grid.Cell(1, 4).Text = "套型建筑面积 S1+S2";
			grid.Cell(1, 5).Text = "阳台面积";
			grid.Cell(1, 6).Text = "套数 N";
			grid.Cell(1, 7).Text = "套型总面积(S1+S2)*N";
			grid.Cell(1, 8).Text = "比例";
			int num2 = 2;
			for (int i = 0; i < HSAAData.Count; i++)
			{
				HouseSuiteAreaAnalyzeData houseSuiteAreaAnalyzeData2 = HSAAData[i];
				grid.Cell(num2, 1).Text = houseSuiteAreaAnalyzeData2.m_StatisticalRange;
				num2++;
				for (int j = 0; j < houseSuiteAreaAnalyzeData2.m_Data.Count; j++)
				{
					HouseSuiteAreaAnalyzeListBySuite houseSuiteAreaAnalyzeListBySuite2 = houseSuiteAreaAnalyzeData2.m_Data[j];
					grid.Cell(num2, 1).Text = " " + houseSuiteAreaAnalyzeListBySuite2.m_SuiteName;
					num2++;
					for (int k = 0; k < houseSuiteAreaAnalyzeListBySuite2.m_Data.Count; k++)
					{
						List<string> lstValue = houseSuiteAreaAnalyzeListBySuite2.m_Data[k].ToStrList();
						this.InsertDataByRow(lstValue, 3, ref grid, ref num2);
					}
					List<string> lstValue2 = houseSuiteAreaAnalyzeListBySuite2.m_Footing.ToStrList();
					this.InsertDataByRow(lstValue2, 2, ref grid, ref num2);
				}
				List<string> lstValue3 = houseSuiteAreaAnalyzeData2.m_SumFooting.ToStrList();
				this.InsertDataByRow(lstValue3, 1, ref grid, ref num2);
			}
		}

        private void InsertDataByRow(List<string> lstValue, int nClass, ref FlexCell.Grid grid, ref int nRow)
		{
			for (int i = 0; i < lstValue.Count; i++)
			{
				if (i == 0)
				{
					string str = "";
					for (int j = 1; j < nClass; j++)
					{
						str += " ";
					}
					grid.Cell(nRow, i + 1).Text = str + lstValue[i];
				}
				else
				{
					grid.Cell(nRow, i + 1).Text = lstValue[i];
				}
			}
			nRow++;
		}

		private ExternalCommandData m_Revit;
	}
}
